package Day2025_03_23;

import java.util.Scanner;

public class NowCoderDP41 {
    static int n;
    static int V;
    static int[] v;
    static int[] w;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        V = sc.nextInt();
        v = new int[n];
        w = new int[n];
        for (int i = 0; i < n; i++) {
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }

        int num1, num2;
        num1 = num1();
        num2 = num2();

        System.out.println(num1);
        System.out.println(num2);

    }

    private static int num1 () {
        int[][] dp = new int[n + 1][V + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= V; j++) {
                dp[i][j] = dp[i - 1][j];
                if (j - v[i - 1] >= 0) dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
            }
        }
        return dp[n][V];
    }

    private static int num2() {
        int[][] dp = new int[n + 1][V + 1];
        for (int i = 0; i <= V; i++) dp[0][i] = -1;
        dp[0][0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= V; j++) {
                dp[i][j] = dp[i - 1][j];
                if (j - v[i - 1] >= 0 && dp[i - 1][j - v[i - 1]] != -1) dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
            }
        }
        return dp[n][V] == -1 ? 0 : dp[n][V];
    }
}
